package dao;

import java.util.HashMap;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.TypedQuery;

import basicas.Compra;
import basicas.Passe;


public class DAOPasse extends DAOGenerico<Passe> implements IDAOPasse{
	
    protected EntityManager entityManager; 
    
    @SuppressWarnings("unchecked") 
    public DAOPasse(){ 
    	HashMap<String, String> properties = new HashMap<String, String>();
    	properties.put("ConnectionDriverName", "com.mysql.jdbc.Driver"); 
    	EntityManagerFactory emf = Persistence.createEntityManagerFactory("psc_projeto", properties); 
    	entityManager = emf.createEntityManager(); 
   
    } 
    
    @Override
    public List<Passe> consultaPorCompra(Compra c){
        try { 
            String sql = "Select p from Passe p WHERE p.Compra = :n"; 
            TypedQuery<Passe> query = entityManager.createQuery(sql, Passe.class); 
            query.setParameter("n", c);
            return query.getResultList(); 
        } catch (Exception e) { 
            e.printStackTrace(); 
        } 
        return null; 
    }

}
